#include "Maths.h"
#include <cmath>

#define DOT(v,q) ((v)[0] * (q)[0] + (v)[1] * (q)[1] + (v)[2] * (q)[2])

bool Maths::Equals( float value1, float value2, float tolerance )
{
	float value = (value2-value1) * ((value2-value1) > 0 ? 1 : -1); 
	return (value < tolerance);
}
bool Maths::Equals( double value1, double value2, double tolerance )
{
	double value = (value2-value1) * ((value2-value1) > 0 ? 1 : -1); 
	return (value < tolerance);
}
void Maths::CrossProduct(float* out, float* b, float* c)
{
	out[0] = b[1]*c[2] - c[1]*b[2];
	out[1] = b[2]*c[0] - c[2]*b[0];
	out[2] = b[0]*c[1] - c[0]*b[1];
}

float Maths::Dot( float* a, float* b )
{
	return DOT(a, b);
}

void Maths::Normalize(float *a)
{
	float normallen = sqrt(DOT(a, a));
	a[0] /= normallen;
	a[1] /= normallen;
	a[2] /= normallen;
}